<template>
    <div>
        <page-header title="用户信息" />
        <page-main>
            <el-card class="box-card">
                <el-button class="pull-right" type="primary" size="small" icon="el-icon-plus" @click="dialogVisible = true">创建用户</el-button>
                <hr>
                <el-table :data="tableData" border style="width: 100%;">
                    <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px">
                    </el-table-column>
                    <el-table-column label="用户名" prop="name">
                    </el-table-column>
                    <el-table-column prop="name" label="姓名">
                    </el-table-column>
                    <el-table-column prop="phone" label="联系电话">
                    </el-table-column>
                    <el-table-column prop="date" label="创建日期" sortable
                                     width="180"
                                     column-key="date"
                                     :filter-method="filterHandler">
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    :current-page.sync="currentPage"
                    :page-size="100"
                    :total="1000"
                    layout="total, prev, pager, next"
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange">
                </el-pagination>
            </el-card>
        </page-main>
        <el-dialog
            :title="title"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">

            <el-form ref="form" :model="userForm" size="small" label-width="80px">
                <el-form-item label="用户名">
                    <el-input v-model="userForm.user"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="userForm.name"></el-input>
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="userForm.phone"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" size="small" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'UserPage',
    data() {
        return {
            title: '新增',
            dialogVisible: false,
            currentPage: 1,
            userForm: {},
            tableData: [{
                date: '2021-05-02',
                name: '王小虎'
            }, {
                date: '2021-05-04',
                name: '王二虎'
            }, {
                date: '2021-05-01',
                name: '王三虎'
            }, {
                date: '2021-05-03',
                name: '王四虎'
            }]
        }
    },
    methods: {
        handleClose(done) {
            // this.$confirm('确认关闭？')
            done()
        },
        handleEdit(index, row) {
            console.log(index, row)
        },
        handleDelete(index, row) {
            console.log(index, row)
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`)
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`)
        }
    }
}
</script>

<style>
    .text {
        font-size: 14px;
    }
    .item {
        margin-bottom: 18px;
    }
    .clearfix::before,
    .clearfix::after {
        display: table;
        content: "";
    }
    .clearfix::after {
        clear: both;
    }
    .box-card {
        width: 100%;
    }
</style>

